package operation;

import data.Data;
import data.DataBase;


public class Register implements IOperation {
    @Override
    public void work(DataBase dataBase) {
        System.out.println("核酸预约登记！");

        System.out.print("请输入你的姓名：");
        String name = scanner.nextLine();
        System.out.print("请输入你的身份证号：");
        String id = scanner.nextLine();
        System.out.print("请输入你的手机号：");
        String phone = scanner.nextLine();
        System.out.print("请输入预约类型：(单采/混采)：");
        String type = scanner.nextLine();

        //判断是否预约过-按id在DataBase查找
        int currentSize=dataBase.getContainSize();
        for (int i = 0; i < currentSize; i++) {
            if (dataBase.getData(i).getId().equals(id)) {
                System.out.println("已存在身份证号为："+id+"的预约信息！");
                return;
            }
        }

        Data data = new Data(name,id,phone,type);
        dataBase.setData(data);
        data.setOrdered(true);
        dataBase.setContainSize(currentSize+1);//踩坑了
        System.out.println("预约成功！");

    }
}
